//index.js
//获取应用实例
var app = getApp(),
a=app.requirejs('core');
Page({
  data: {
    display:true,
    show:false,
    list:[],
    page:1,
    loaded:false,
    imagePath: 'http://ddfwz.sssvip.net/asmce/kanjia/timg.gif'
  },
  onGotUserInfo: function () {
    var that = this,
      e = app.getCache("userinfo");
    if (!e) {
      that.setData({
        display: false
      })
      app.getUserInfo(function(){
        that.getList();
      });
    }
  },
  onLoad: function () {
    var that = this,
    e = app.getCache("userinfo");
    if(e){
      that.setData({
        display: false
      });
      that.getList();
    }
  },
  onShow:function(){
      var d=app.getCache('shop_info'),
        display = this.data.display;
      if (!display && d){
        this.getList();
      }
  },
  getList:function(){
    var that = this,
    i = getApp().getCache("userinfo");
    if (i) {
      a.get('Shop/info', {
        uid: i.uid
      }, function (t) {
        if (t.code == 0) {
          app.globalData.shop_id = t.info.shop_id;
          that.setData({
            info: t.info,
            show: true
          })
          a.get('User/getwxcode', {
            shop_id: t.info.shop_id
          }, function (i) {
            that.setData({
              image_url: i
            })
          })
        } else {
          a.alert(t.msg);
        }
      }, !that.data.show)
    } 
  },
  url:function(e){
    var id=a.pdata(e).id;
    a.jump('/pages/add_card/index?id='+id)
  },
  phone: function (e) {
    a.phone(e)
  },
  address: function () {
    var data = this.data.info.shop;
    if (data.longitude && data.latitude) {
      a.tx_map(data.latitude, data.longitude, data.name);
    }
  },
  img_big: function () {
    if (this.data.image_url) {
      a.previewImage(this.data.image_url)
    }
  },
  /**
    * 下拉刷新
    */
  onPullDownRefresh: function () {
    // this.data.display || this.setData({
    //     list: [],
    //     page: 1,
    //     loaded: false
    //   }),
    //   this.getList();
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    // console.log('加载更多')
    // this.data.loaded || this.getList()
  },
  url:function(){
    a.jump('/pages/add_card/index');
  },
  onShareAppMessage:function(){

  }
})
